package com.heo.queue.task;

import java.util.Date;

import com.heo.pojo.DeviceInfoEntity;
import com.heo.protocol.packet.BasePacket;

public class SendTask
{
  private BasePacket basePacket;// 要发送给设备的数据包
  private DeviceInfoEntity deviceInfoEntity;// 设备对象
  private ReSendInfo reSendInfo = new ReSendInfo();// 重发信息，如果为null，则表示该数据不需要重发

//  public SendTask(BasePacket basePacket, DeviceInfoEntity deviceInfoEntity, int maxReSendCount, long expireTime)
//  {
//    this.basePacket = basePacket;
//    this.deviceInfoEntity = deviceInfoEntity;
//    ReSendInfo reSendInfo = new ReSendInfo();
//    reSendInfo.setExpireTime(expireTime);
//    reSendInfo.setMaxReSendCount(maxReSendCount);
//    this.reSendInfo = reSendInfo;
//  }
  
  /**
   * 使用配置参数里的超时时间和重发次数
   * @param basePacket
   * @param deviceInfoEntity
   */
  public SendTask(BasePacket basePacket, DeviceInfoEntity deviceInfoEntity)
  {
    this.basePacket = basePacket;
    this.deviceInfoEntity = deviceInfoEntity;
  }
  
  /**
   * 设置重发
   */
  public void setReSend()
  {
    if (reSendInfo == null)
    {
      return;
    }
    reSendInfo.setLastSendTime(new Date().getTime());
    reSendInfo.setReSendCount(reSendInfo.getReSendCount() + 1);
  }

  public BasePacket getBasePacket()
  {
    return basePacket;
  }

  public void setBasePacket(BasePacket basePacket)
  {
    this.basePacket = basePacket;
  }

  public DeviceInfoEntity getDeviceInfoEntity()
  {
    return deviceInfoEntity;
  }

  public void setDeviceInfoEntity(DeviceInfoEntity deviceInfoEntity)
  {
    this.deviceInfoEntity = deviceInfoEntity;
  }

  public ReSendInfo getReSendInfo()
  {
    return reSendInfo;
  }

  public void setReSendInfo(ReSendInfo reSendInfo)
  {
    this.reSendInfo = reSendInfo;
  }

}
